home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / uwserver.zip / uwserver.tar / lib / uw_rsetopt.c < prev    next >
C/C++ Source or Header  |  1991-01-25  |  2KB  |  92 lines

  1. /*
  2.  *    uw library - uw_rsetopt
  3.  *
  4.  * Copyright 1986 by John D. Bruner.  All rights reserved.  Permission to
  5.  * copy this program is given provided that the copy is not sold and that
  6.  * this copyright notice is included.
  7.  */
  8. #include <sys/types.h>
  9. #include <sys/socket.h>
  10. #include <sys/un.h>
  11. #include <sys/ioctl.h>
  12. #include <sys/uio.h>
  13. #include <sys/file.h>
  14. #include <strings.h>
  15. #include <signal.h>
  16. #include "openpty.h"
  17.  
  18. #include "uwlib.h"
  19.  
  20. extern char *malloc();
  21. extern char *getenv();
  22.  
  23. uw_rsetopt(uwid, optnum, optval)
  24. uwid_t uwid;
  25. uwopt_t optnum;
  26. union uwoptval *optval;
  27. {
  28.     register int sd;
  29.     register struct uwipc *uwip;
  30.     char *portal;
  31.     struct iovec iov;
  32.     struct msghdr msg;
  33.     struct sockaddr_un sa;
  34.  
  35.     /*
  36.      * Set a window option on a remote window (that is, one for which
  37.      * we do not have a control fd).
  38.      */
  39.  
  40.     /*
  41.      * Create a UNIX-domain socket.
  42.      */
  43.     if (!(portal=getenv("UW_UIPC"))) {
  44.         uwerrno = UWE_NXSERV;
  45.         return(-1);
  46.     }
  47.  
  48.     if ((sd=socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
  49.         uwerrno = UWE_ERRNO;
  50.         return(-1);
  51.     }
  52.     sa.sun_family = AF_UNIX;
  53.     (void)strncpy(sa.sun_path, portal, sizeof sa.sun_path-1);
  54.     sa.sun_path[sizeof sa.sun_path-1] = '\0';
  55.  
  56.  
  57.     /*
  58.      * Construct the datagram we will send later.
  59.      */
  60.     uwip = (struct uwipc *)malloc(sizeof(struct uwipc));
  61.     if (uwip == (struct uwipc *)0) {
  62.         uwerrno = UWE_NOMEM;
  63.         return(-1);
  64.     }
  65.     uwip->uwip_cmd = UWC_OPTION;
  66.     uwip->uwip_len = sizeof(struct uwipc);
  67.     uwip->uwip_option.uwop_id = uwid;
  68.     uwip->uwip_option.uwop_cmd = UWOC_SET;
  69.     uwip->uwip_option.uwop_opt = optnum;
  70.     uwip->uwip_option.uwop_val = *optval;
  71.  
  72.     /*
  73.      * Pass the file descriptor to the window server.
  74.      */
  75.     iov.iov_base = (char *)uwip;
  76.     iov.iov_len = uwip->uwip_len;
  77.     msg.msg_name = (caddr_t)&sa;
  78.     msg.msg_namelen = sizeof sa.sun_family + strlen(sa.sun_path);
  79.     msg.msg_iov = &iov;
  80.     msg.msg_iovlen = 1;
  81.     msg.msg_accrights = (caddr_t)0;
  82.     msg.msg_accrightslen = 0;
  83.     if (sendmsg(sd, &msg, 0) < 0) {
  84.         free((char *)uwip);
  85.         uwerrno = UWE_ERRNO;
  86.         return(-1);
  87.     }
  88.     free((char *)uwip);
  89.     uwerrno = UWE_NONE;
  90.     return(0);
  91. }
  92.